﻿#include "./CameraFactory.h"
#include "./CameraScreen.h"
#include <QCameraInfo>
#include <QApplication>
#include <QDesktopWidget>
namespace Qly{

QList<IndustryCameraInfo> CameraFactory::availableCameras()
{
    QList<QScreen *> list = QGuiApplication::screens();
    QList<Qly::IndustryCameraInfo> infos;
    foreach (QScreen * s, list)
    {
        Qly::IndustryCameraInfo info;
        info.type = Qly::CameraType::SYS_SCREEN;
        info.cameraID = s->serialNumber();
        info.vendorName = s->manufacturer();
        info.modelName = s->model();
        info.description = s->name();
        infos << info;
    }

    return infos;
}

IndustryCamera *CameraFactory::findCameraByName(QString name, QObject *parent)
{
    Qly::CameraScreen * pCamera = new Qly::CameraScreen(parent);
    if( !pCamera->openCameraByName(name) )
    {
        pCamera = nullptr;
        qDebug() << "No Screen Find";
    }

    return pCamera;
}

IndustryCamera *CameraFactory::defaultCamera(QObject *parent)
{
    Qly::CameraScreen * pCamera = new Qly::CameraScreen(parent);
    if( !pCamera->openDefaultCamera())
    {
        pCamera = nullptr;
        qDebug() << "No Screen Find";
    }

    return pCamera;
}

QString CameraFactory::vendorName()
{
    return QString("Screen");
}

} //namespace Qly

Qly::CameraFactoryInterface *CreateInstance()
{
    Qly::CameraFactory * cameraFactory = new Qly::CameraFactory();
    return cameraFactory;
}

void Release(Qly::CameraFactoryInterface *p)
{
    delete p;
}



QList<Qly::IndustryCameraInfo> Qly::CameraFactory::availableCameras(CameraType type)
{
    if( type == CameraType::SYS_SCREEN )
    {
        return availableCameras();
    }
    return QList<Qly::IndustryCameraInfo>();
}



QList<Qly::IndustryCameraInfo> Qly::CameraFactory::availableCameras(QSet<CameraType> types)
{
    if( types.contains(CameraType::SYS_SCREEN) )
    {
        return availableCameras();
    }
    return QList<Qly::IndustryCameraInfo>();
}

